package com.jia.interviewPro;

/**
 * @program: Leetcode
 * @description:  https://leetcode-cn.com/problems/binode-lcci/
 * @author: STU756
 * @create: 2020-09-03 15:41
 */
public class Pro1712 {
    TreeNode head, pre;
    public TreeNode convertBiNode(TreeNode root) {
        inorder(root);
        //尾节点的left要置为null
        if(pre != null)
            pre.left = null;
        return head;
    }
    private void inorder(TreeNode root) {
        if(root == null) return ;
        else {
            inorder(root.left);
            if(head == null) {
                head = root;
            }
            if(pre!=null) {
                pre.right = root;
                pre.left = null;
            }
            pre = root;
            inorder(root.right);
        }
    }
}

